<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>register</title>
</head>
<body>
    <form action="">
        <input id="user" type="text" name="user" placeholder="请输入用户名"><br>
        <input id="pass" type="password" name="pass" placeholder="请输入密码"><br>
        <input id="btn"  type="button" value="注册">
    </form>
    <script src="jquery.min.js"></script>
    <script>
        
        $('#btn').on('click',()=>{
            $.ajax({
                url: '/reg',
                dataType: 'json',
                data: {
                    user: $('#user').val(),
                    pass: $('#pass').val()
                },
                success (res) {
                    if (res.code) {
                        alert('error - ' + res.msg);
                    } else {
                        alert('Rgister Success');
                    }
                },
                error (err) {
                    alert('failed');
                }
            })
        });
    </script>
</body>
</html>